package fr.perso.ppo.springintegration.event;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.integration.Message;
import org.springframework.integration.MessageHandlingException;
import org.springframework.integration.support.MessageBuilder;

public class RecycleNewPaymentHandler {
	
private static Logger log = LoggerFactory.getLogger(RecycleNewPaymentHandler.class);
	
	
	public Message<?> recycle(Message<?> msg) throws Exception {
		log.warn("==================get into recycling error /////////////////////");
		MessageHandlingException payload = (MessageHandlingException) msg.getPayload();
		log.warn(payload.getMessage(),payload.getCause());
		log.warn("--------------------------------- {}" , payload.getFailedMessage().getPayload());
		//Message<?> originalMsg = (Message<?>) payload.getFailedMessage().getPayload();
		String originalMsg =  (String) payload.getFailedMessage().getPayload();
		log.debug("************************this is the original message {}*************************",originalMsg.toString());
		
		return MessageBuilder.withPayload(originalMsg).build();
	}

}
